<?php include PATH_TPL."/admin/tpl.header.phtml"?>
<div class="main-container inner">
    <div class="main-content">
        <div class="container-fluid">
            <div class="row bt">
                <div class="col-lg-12 bg">
                    <ol class="breadcrumb">
                        <li class="active">
                            <i class="fa  fa-fw fa-reorder"></i>添加新闻
                        </li>
                    </ol>
                </div>
            </div>
            <div id="page-wrapper">
                <div class="container-fluid col-md-7 col-sx-12">
                    <form action="/admin_article/add" method="post" enctype="multipart/form-data">
                        <div class="form-group ">
                            <label for="title">新闻标题</label>
                            <input type="text" placeholder="输入新闻标题" id="title" class="form-control" name="title">
                        </div>
                        <div class="form-group">
                            <label for="img">新闻封面图片</label>
                            <input type="file" id="file_input" name="img" class="file-loading" data-show-preview="false">
                        </div>
                        <div class="form-group">
                            <label for="descriptions">描述</label>
                            <textarea id="descriptions" style="height: 100px;resize:none;" class="form-control" name="descriptions" placeholder="输入描述（选填）"></textarea>
                        </div>
                        <div class="form-group">
                            <label for="initview">初始化浏览量</label>
                            <input type="text" placeholder="0" id="source" class="form-control" name="initview">
                        </div>
                        <div class="form-group">
                            <label for="content">新闻内容</label>
                            <!-- 加载编辑器的容器 -->
                            <script id="container" name="content" type="text/plain"></script>
                        </div>
                        <div class="form-group">
                            <label>推送时间</label>
                            <div class="input-group date form_date col-md-12" data-date="<?=date('Y-m-d H-i-s',time())?>" data-date-format="yyyy-mm-dd hh:ii:ss" data-link-field="push_time">
                            <input class="form-control" size="16" type="text" value="<?=date('Y-m-d H:i:s',strtotime(date('Y-m-d',time()))+20*60*60)?>" readonly>
                                <span class="input-group-addon"><span class="glyphicon glyphicon-remove"></span></span>
                                <span class="input-group-addon"><span class="glyphicon glyphicon-th"></span></span>
                            </div>
                            <input type="hidden" id="push_time" value="<?=date('Y-m-d H:i:s',strtotime(date('Y-m-d',time()))+20*60*60)?>" name="push_time"/><br/>
                        </div>
                        <div class="form-group">
                            <label for="status">是否发布</label>
                            <input type="radio" name="status" value='1'> 是
                            <input type="radio" name="status" value='0' checked> 否
                        </div>

                        <button class="btn btn-primary demo_2" type="button" id="submit">添加</button>
                    </form>
                </div>
                <div class="container-fluid col-md-5">
                    <div class="images text-center" id="img_view">
                    </div>
                </div>
            </div>
        </div>
        <div class="subviews">
            <div class="subviews-container"></div>
        </div>
    </div>
    <!-- end: PAGE -->
</div>
<!-- end: MAIN CONTAINER -->
<script type="text/javascript" src="/plugins/datetimepicker/js/bootstrap-datetimepicker.js"></script>
<script type="text/javascript" src="/plugins/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script type="text/javascript">
$('.form_date').datetimepicker({
    language:  'zh-CN',
    weekStart: 1,
    todayBtn:  1,
    autoclose: 1,
    todayHighlight: 1,
    startView: 2,
    minView: 0,
    dateStart:'2016-01-01',
    dateEnd:'2050-12-30',
    pickerPosition: "top-right",
    format:'yyyy-mm-dd hh:ii:ss',
    forceParse: 0
});
</script>


<!-- 配置文件 -->
<script type="text/javascript" src="/plugins/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="/plugins/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('container',{
        toolbars: [
            ['fullscreen', 'source', 'undo', 'redo','bold', 'italic', 'underline','fontborder', 'strikethrough', '|','simpleupload', 'insertimage','attachment','emotion','link','unlink', '|', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote','searchreplace', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc'],
            ['inserttable','insertrow', 'insertcol','mergeright', 'mergedown','deleterow', 'deletecol','splittorows','splittocols', 'splittocells','deletecaption','inserttitle', 'mergecells', 'deletetable','insertparagraphbeforetable', 'paragraph','fontsize','fontfamily']
        ],
        initialFrameHeight:260,
        zIndex:1000,
    });
</script>
<script>
$(document).on('ready', function() {
    $("#file_input").fileinput({
        language:'zh',
        overwriteInitial: false,
        showUpload: false,
        showRemove: false,
        browseLabel: "上传图片",
    });
});
</script>

<script>
$(function(){
    var options={
        beforeSubmit : showRequest,    // 提交前的回调函数
        success : showResponse,    // 提交后的回调函数
        dataType : "json",    // html（默认）、xml、script、json接受服务器端返回的类型
    }
    function showRequest(formData, jqForm, options){
        return true;
    }
    function showResponse(responseText,statusText){
        cg_alert_add(responseText,'/admin_article','/admin_article/add');
    }
    $('#submit').click(function() {
        $('form').ajaxSubmit(options);
        return false;

    });
});
var result = document.getElementById("img_view");
var input = document.getElementById("file_input");

if(typeof FileReader==='undefined'){
   result.innerHTML = "抱歉，你的浏览器不支持 FileReader";
   input.setAttribute('disabled','disabled');
}else{
   input.addEventListener('change',readFile,false);
}
function readFile(){
   var file = this.files[0];
   if(!/image\/\w+/.test(file.type)){
       alert("文件必须为图片！");
       return false;
   }
   var reader = new FileReader();
   reader.readAsDataURL(file);
   reader.onload = function(e){
       result.innerHTML = '<img src="'+this.result+'" alt="" width="400px"/>'
   }
}
</script>
<?php include PATH_TPL."/admin/tpl.footer.phtml"?>
